/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.geoviewer.jxmap.layerlist;

import java.awt.Component;
import java.awt.Dimension;
import static org.junit.Assert.*;
import org.junit.Test;
import org.openide.explorer.view.ListView;
import org.uispec4j.Panel;
import org.uispec4j.UISpec4J;
import org.uispec4j.finder.ComponentMatcher;

/**
 *
 * @author Timon Veenstra
 */
public class LayerListPanelIT {

    static {
        UISpec4J.init();
    }
    private final ListViewComponentMatcher listViewMatcher = new ListViewComponentMatcher();

    @Test
    public void testPanel() {
        Panel panel = new Panel(new LayerListPanel());
        assertTrue(panel.containsComponent(listViewMatcher).isTrue());

        Dimension panelSize = panel.getAwtComponent().getPreferredSize();
        Component listView = panel.findSwingComponent(listViewMatcher);
        Dimension listSize = listView.getPreferredSize();
        assertEquals("width of panel and list should be equal",panelSize.width, listSize.width);
     }

    class ListViewComponentMatcher implements ComponentMatcher {

        @Override
        public boolean matches(Component component) {
            return (component instanceof ListView);
        }
    }
}
